<?php

class Default_Model_User extends Zend_Db_Table_Abstract {

    protected $_name = 'user';

    public function getDataById($userId){
        $select = $this->select(self::SELECT_WITH_FROM_PART)->columns(array('password'))->where('Id=?',$userId);
        return $this->fetchRow($select);
    }
    public function getDataUserById($userId){        
        $query = $this->select()                        
                        ->from($this->_name)
                        ->where('id = ?',(int)$userId);                        
        return $this->fetchRow($query);
    }
    public function getDataByUsername($username){
        $query = $this->select()
            ->from($this->_name)
            ->where('username = ?', $username);
        return $this->fetchRow($query);
    }
    public function addData($data=array()){
        $idAdd = $this->insert($data);
        return $idAdd;
    }
    public function getDataByEmail($email){
        $query = $this->select()
            ->from($this->_name)
            ->where('email = ?', $email);
        return $this->fetchRow($query);
    }
    public function getDataByMobile($mobile){
        $query = $this->select()
            ->from($this->_name)
            ->where('mobile = '.$mobile.'');
        return $this->fetchRow($query);
    }
    public function updateGold($id = '',$data){
        $data = array('gold'            =>$data['gold']);                    
        return $this->update($data, 'id = '.(int)$id);
    }
    public function updateData($id = '',$data){        
        $data = array('fullname'    =>$data['fullname'],
                        'mobile'    =>$data['mobile'],
                        'address'   =>$data['address']);                                            
        return $this->update($data, 'id = '.(int)$id);
    }
    public function updatePass($id, $password){
        //pr(md5($password));
        $data = array('password' => md5($password));
        return $this->update($data,'id='.(int)$id);
    } 
    public function updateLogin($id){
        //pr(md5($password));
        $data = array('last' => time(),'random'=>'');
        return $this->update($data,'id='.(int)$id);
    }              
    public function updateRandom($id,$rand){        
        $data = array('random' => $rand);
        return $this->update($data,'id='.(int)$id);
    }

} 